package entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
public class Orcamento extends EntityManaged implements Serializable {

    private static final long serialVersionUID = 1082824403447060113L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    protected Long id;

    @Temporal(TemporalType.DATE)
    private Date dataInicial;

    @Temporal(TemporalType.DATE)
    private Date dataFinal;

    private BigDecimal valor;

    @Transient
    private BigDecimal valorUsado;

    @OneToOne
    private CategoriaTransacao categoriaTransacao;

    private BigDecimal percentUsado;

    @Override
    public Long getId() {
	return id;
    }

    public Date getDataInicial() {
	return dataInicial;
    }

    public Date getDataFinal() {
	return dataFinal;
    }

    public BigDecimal getValor() {
	return valor;
    }

    public CategoriaTransacao getCategoriaTransacao() {
	return categoriaTransacao;
    }

    public void setId(Long id) {
	this.id = id;
    }

    public void setDataInicial(Date dataInicial) {
	this.dataInicial = dataInicial;
    }

    public void setDataFinal(Date dataFinal) {
	this.dataFinal = dataFinal;
    }

    public void setValor(BigDecimal valor) {
	this.valor = valor;
    }

    public void setCategoriaTransacao(CategoriaTransacao categoriaTransacao) {
	this.categoriaTransacao = categoriaTransacao;
    }

    @Override
    public int hashCode() {
	final int prime = 31;
	int result = super.hashCode();
	result = prime
		* result
		+ ((categoriaTransacao == null) ? 0 : categoriaTransacao
			.hashCode());
	result = prime * result
		+ ((dataFinal == null) ? 0 : dataFinal.hashCode());
	result = prime * result
		+ ((dataInicial == null) ? 0 : dataInicial.hashCode());
	result = prime * result + ((id == null) ? 0 : id.hashCode());
	result = prime * result + ((valor == null) ? 0 : valor.hashCode());
	return result;
    }

    @Override
    public boolean equals(Object obj) {
	if (this == obj)
	    return true;
	if (!super.equals(obj))
	    return false;
	if (getClass() != obj.getClass())
	    return false;
	Orcamento other = (Orcamento) obj;
	if (categoriaTransacao == null) {
	    if (other.categoriaTransacao != null)
		return false;
	} else if (!categoriaTransacao.equals(other.categoriaTransacao))
	    return false;
	if (dataFinal == null) {
	    if (other.dataFinal != null)
		return false;
	} else if (!dataFinal.equals(other.dataFinal))
	    return false;
	if (dataInicial == null) {
	    if (other.dataInicial != null)
		return false;
	} else if (!dataInicial.equals(other.dataInicial))
	    return false;
	if (id == null) {
	    if (other.id != null)
		return false;
	} else if (!id.equals(other.id))
	    return false;
	if (valor == null) {
	    if (other.valor != null)
		return false;
	} else if (!valor.equals(other.valor))
	    return false;
	return true;
    }

    public BigDecimal getValorUsado() {
	return valorUsado;
    }

    public void setValorUsado(BigDecimal valorUsado) {
	this.valorUsado = valorUsado;
    }

    public BigDecimal getPercentUsado() {
	return percentUsado;
    }

    public void setPercentUsado(BigDecimal percentUsado) {
        this.percentUsado = percentUsado;
    }

}
